from django.test import TestCase
from django.db import models
import xlrd
import os
# Create your tests here.

# 读表测试
if __name__ == "__main__":
    test = '1'
    print(test if test != '' else 0)

    # filename = "temp.xls"
    # # 打开xls文件
    # file_xlsx = xlrd.open_workbook(os.getcwd() + "\\temp\\" + filename)
    # # 获取所有sheet表
    # all_sheet = file_xlsx.sheets()
    # # 获取第一张表
    # sheet1 = all_sheet[0]
    # # sheet1_name = sheet1.name
    # # 获取表的行数，同理sheet1.ncols表的列数，sheet1.name获取表的名字
    # sheet1_rows = sheet1.nrows
    # value_list = []
    # for i in range(1, sheet1_rows):
    #     if sheet1.row_values(i):
    #         value_list.append(models.EvaluationIndex(
    #             name=sheet1.row_values(i)[0],
    #             index=int(sheet1.row_values(i)[21])
    #         ))
    # models.EvaluationIndex.objects.bulk_create(value_list)
    # def create_risk_evlation(request):
    #     filename = "temp.xls"
    #     # 打开xls文件
    #     file_xlsx = xlrd.open_workbook(os.getcwd() + "\\temp\\" + filename)
    #     # 获取所有sheet表
    #     all_sheet = file_xlsx.sheets()
    #     # 获取第一张表
    #     sheet1 = all_sheet[0]
    #     # sheet1_name = sheet1.name
    #     # 获取表的行数，同理sheet1.ncols表的列数，sheet1.name获取表的名字
    #     sheet1_rows = sheet1.nrows
    #     value_list = []
    #     for i in range(1, sheet1_rows):
    #         if sheet1.row_values(i):
    #             value_list.append(models.EvaluationIndex(
    #                 name=sheet1.row_values(i)[0],
    #                 index=int(sheet1.row_values(i)[21])
    #             ))
    #     models.EvaluationIndex.objects.bulk_create(value_list)
    #     # 打开csv文件
    #     return JsonResponse({"status": "200", "msg": "post credit risk file sucess."})

    # def createUserByExcel(request):
    #     # 打开文件
    #     file_xlsx = xlrd.open_workbook(os.getcwd() + '/static/files/' + filename)
    #     # 获取所有sheet表
    #     all_sheet = file_xlsx.sheets()
    #     # 获取第一张表
    #     sheet1 = all_sheet[0]
    #     # sheet1_name = sheet1.name
    #     # 获取表的行数，同理sheet1.ncols表的列数，sheet1.name获取表的名字
    #     sheet1_rows = sheet1.nrows
    #     value_list = []
    #     for i in range(1, sheet1_rows):

    #         if sheet1.row_values(i):
    #             value_list.append(models.User(
    #                 name=sheet1.row_values(i)[0],
    #                 age=int(sheet1.row_values(i)[1])
    #                 # 此处需要注意：models中age为Interge，存储时age要转换成int类型
    #             ))
    #     models.User.objects.bulk_create(value_list)
